package com.lucene;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.nvm.util.ResourceReader;

import com.lucene.index.Position;

/**
 * @author Smile.Wu
 * @date 2016年1月18日  下午1:46:55
 */
public class LuceneUtil {

	public static final String INDEX_FOLDER = "D:/lucene/index/";
	public static final String SRC_FOLDER = "D:/lucene/";
	
	public static List<Position> readPosition() {
		List<Position> list = new ArrayList<>(0);
		ResourceReader reader = new ResourceReader(new File(SRC_FOLDER + "src.txt"), "UTF-8");
		try {
			reader.load();
			
			String line = null;
			
			while((line = reader.readLine()) != null) {
				String[] vls = line.split(",");
				long pid = Long.parseLong(vls[0]);
				String title = vls[1];
				long cityId = Long.parseLong(vls[2]);
				Position p = new Position();
				
				p.setCityId(cityId);
				p.setTitle(title);
				p.setPid(pid);
				list.add(p);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
}
